<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="容器类型编码:">
        <el-input v-model="queryParams.conTypeSeq" size="small" placeholder="请输入容器类型编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大载重:">
        <el-input v-model="queryParams.maxCapacity" size="small" placeholder="请输入最大载重" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大容积:">
        <el-input v-model="queryParams.maxVol" size="small" placeholder="请输入最大容积" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="长:">
        <el-input v-model="queryParams.length" size="small" placeholder="请输入长" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="高:">
        <el-input v-model="queryParams.height" size="small" placeholder="请输入高" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="宽:">
        <el-input v-model="queryParams.width" size="small" placeholder="请输入宽" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.version" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainBoxType:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainBoxType:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainBoxType:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['module:tWhContainBoxType:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="容器类型编码" align="center" prop="conTypeSeq" />
      <el-table-column label="最大载重" align="center" prop="maxCapacity" />
      <el-table-column label="最大容积" align="center" prop="maxVol" />
      <el-table-column label="储物类型" align="center" prop="holdMaterialType" />
      <el-table-column label="长" align="center" prop="length" />
      <el-table-column label="高" align="center" prop="height" />
      <el-table-column label="宽" align="center" prop="width" />
      <el-table-column label="" align="center" prop="version" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['web:tbWmsContainBoxType:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['web:tbWmsContainBoxType:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="tbWmsContainBoxTypeFormDialog.title" :visible.sync="tbWmsContainBoxTypeFormDialog.visible" :close-on-click-modal="false" width="500px" append-to-body>
      <el-form ref="tbWmsContainBoxTypeForm" :model="tbWmsContainBoxTypeFormData" :rules="tbWmsContainBoxTypeFormRules" label-width="80px">
        <el-form-item label="容器名称" prop="name">
          <el-input v-model="tbWmsContainBoxTypeFormData.name" placeholder="请输入容器类型编码" />
        </el-form-item>
        <el-form-item label="容器名称" prop="name">
          <el-input v-model="tbWmsContainBoxTypeFormData.spec" placeholder="请输入容器类型编码" />
        </el-form-item>
        <el-form-item label="最大载重" prop="maxCapacity">
          <el-input v-model="tbWmsContainBoxTypeFormData.maxCapacity" placeholder="请输入最大载重" />
        </el-form-item>
        <el-form-item label="最大容积" prop="maxVol">
          <el-input v-model="tbWmsContainBoxTypeFormData.maxVol" placeholder="请输入最大容积" />
        </el-form-item>
        <el-form-item label="长" prop="length">
          <el-input v-model="tbWmsContainBoxTypeFormData.length" placeholder="请输入长" />
        </el-form-item>
        <el-form-item label="高" prop="height">
          <el-input v-model="tbWmsContainBoxTypeFormData.height" placeholder="请输入高" />
        </el-form-item>
        <el-form-item label="宽" prop="width">
          <el-input v-model="tbWmsContainBoxTypeFormData.width" placeholder="请输入宽" />
        </el-form-item>
        <el-form-item label="" prop="version">
          <el-input v-model="tbWmsContainBoxTypeFormData.version" placeholder="请输入" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmTbWmsContainBoxTypeFormDialog">确 定</el-button>
        <el-button @click="resetTbWmsContainBoxTypeFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TbWmsContainBoxTypeApi from '@/api/web/TbWmsContainBoxTypeApi'

const defaultTbWmsContainBoxTypeFormData = {
  name: null,
  spec:null,
  maxCapacity: null,
  maxVol: null,
  holdMaterialType: null,
  length: null,
  height: null,
  width: null,
  version: null,
}
export default {
  name: 'TbWmsContainBoxTypeList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        name: null,
        spec:null,
        maxCapacity: null,
        maxVol: null,
        holdMaterialType: null,
        length: null,
        height: null,
        width: null,
        version: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      tbWmsContainBoxTypeFormDialog: {
        title: '',
        visible: false
      },
      tbWmsContainBoxTypeFormData: Object.assign({}, defaultTbWmsContainBoxTypeFormData),
      tbWmsContainBoxTypeFormRules: {
        conTypeSeq: [{ required: true, message: '容器类型编码不能为空', trigger: 'blur' }],
        maxCapacity: [{ required: true, message: '最大载重不能为空', trigger: 'blur' }],
        maxVol: [{ required: true, message: '最大容积不能为空', trigger: 'blur' }],
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openTbWmsContainBoxTypeFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TbWmsContainBoxTypeApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openTbWmsContainBoxTypeFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      TbWmsContainBoxTypeApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TbWmsContainBoxTypeApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openTbWmsContainBoxTypeFormDialog(id) {
      this.resetTbWmsContainBoxTypeFormDialog()
      this.tbWmsContainBoxTypeFormDialog.visible = true
      if (id) {
        this.tbWmsContainBoxTypeFormDialog.title = '容器类型-修改'
        TbWmsContainBoxTypeApi.get(id).then(response => {
          this.tbWmsContainBoxTypeFormData = {
            ...this.tbWmsContainBoxTypeFormData,
            ...response.data
          }
        })
      } else {
        this.tbWmsContainBoxTypeFormDialog.title = '容器类型-添加'
      }
    },
    confirmTbWmsContainBoxTypeFormDialog() {
      this.$refs['tbWmsContainBoxTypeForm'].validate(valid => {
        if (valid) {
          if (this.tbWmsContainBoxTypeFormData.id) {
            TbWmsContainBoxTypeApi.edit(this.tbWmsContainBoxTypeFormData).then(response => {
              this.$message.success('修改成功')
              this.tbWmsContainBoxTypeFormDialog.visible = false
              this.handleQuery()
            })
          } else {
            TbWmsContainBoxTypeApi.add(this.tbWmsContainBoxTypeFormData).then(response => {
              this.$message.success('添加成功')
              this.tbWmsContainBoxTypeFormDialog.visible = false
              this.handleQuery()
            })
          }
        }
      })
    },
    resetTbWmsContainBoxTypeFormDialog() {
      this.tbWmsContainBoxTypeFormDialog = {
        title: '',
        visible: false
      }
      this.tbWmsContainBoxTypeFormData = Object.assign({}, defaultTbWmsContainBoxTypeFormData)
      this.resetForm('tbWmsContainBoxTypeForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
